package com.example.gameandroid;

import org.andengine.engine.Engine;
import org.andengine.engine.camera.hud.HUD;
import org.andengine.entity.sprite.ButtonSprite;
import org.andengine.entity.sprite.ButtonSprite.OnClickListener;
import org.andengine.entity.text.Text;
import org.andengine.extension.physics.box2d.PhysicsWorld;
import org.andengine.opengl.font.Font;
import org.andengine.opengl.texture.region.ITiledTextureRegion;

import com.badlogic.gdx.physics.box2d.Body;

public class GameHUD extends HUD{
	
	private ButtonSprite botao;
	private Text pontos; 
	private Text highscore;
	
	public GameHUD(Engine engine, PhysicsWorld physicsWorld, ITiledTextureRegion botaoTexture, float width, float height, 
			final Body bodyPlayer, Font font, final Player player) {
		
		OnClickListener botaoClick = new OnClickListener() {
			@Override
			public void onClick(ButtonSprite pButtonSprite, float pTouchAreaLocalX, float pTouchAreaLocalY) {
				
				if(player.isOnFloor()){
					
					bodyPlayer.applyForce(0, -200, bodyPlayer.getPosition().x, bodyPlayer.getPosition().y);
					player.setOnFloor(false);
					
				}else{
					System.out.println("velY: " + bodyPlayer.getLinearVelocity().y);
					
				}
				
			}
		};
		
		botao = new ButtonSprite(0, 0, botaoTexture, engine.getVertexBufferObjectManager(), botaoClick);
		botao.setPosition(width - botao.getWidth() - 100, height - botao.getHeight() - 30);
		attachChild(botao);
		
		registerTouchArea(botao);
		
		pontos = new Text(40, 0, font, "----------", engine.getVertexBufferObjectManager());
		pontos.setText("0");
		attachChild(pontos);
		
		highscore = new Text(0, 0, font, "----------", engine.getVertexBufferObjectManager()); 
		highscore.setText("900");
		highscore.setPosition(width - highscore.getWidth() * 1.5f, 0);
		attachChild(highscore);
	}
	
	public void setPontos(int pts){
		pontos.setText("" + pts);
	
	}

}
